package cn.lili.modules.order.order.mapper;

import cn.lili.modules.order.order.entity.dos.Trade;
import cn.lili.modules.order.order.entity.vo.OrderSimpleVO;
import cn.lili.modules.order.order.entity.vo.TradeCarVO;
import cn.lili.modules.store.entity.vos.StoreVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 交易数据处理层
 *
 * @author Chopper
 * @since 2020/11/17 7:35 下午
 */
public interface TradeMapper extends BaseMapper<Trade> {

    /**
     * 修改交易金额
     *
     * @param tradeSn 交易编号
     */
    @Update("UPDATE li_trade SET flow_price =(SELECT SUM(flow_price) FROM li_order WHERE trade_sn=#{tradeSn}) WHERE sn=#{tradeSn}")
    void updateTradePrice(String tradeSn);


    /**
     * 修改交易状态
     *
     * @param status  状态
     * @param tradeSn 订单编号
     */
    @Update({"update li_trade set trade_status = #{status} where sn = #{tradeSn}"})
    void updateStatus(String status, String tradeSn);

    /**
     * 获取叫车信息
     *
     * @param tradeSn 交易编号
     */
    @Select("select lt.sn ,lt.car_num ,lt.car_type ,lt.driver_name ,lt.driver_phone ,lt.call_time,lt.call_remark from li_trade lt where lt.sn=#{tradeSn}")
    TradeCarVO getCarVOBySn(String tradeSn);


    /**
     * 查询交易订单简短信息分页
     *
     * @param page         分页
     * @param queryWrapper 查询条件
     * @return 简短订单分页
     */
    @Select("select t.* from li_trade as t ${ew.customSqlSegment}")
    IPage<Trade> queryByParams(IPage<OrderSimpleVO> page, @Param(Constants.WRAPPER) Wrapper<OrderSimpleVO> queryWrapper);

}